<template>
    <section class="dc-edit" v-focus>
        <XdoCard class="xdo-card" :bordered="false">
            <div class="xdo-card-body">
                <XdoForm ref="formItem" class="dc-form" :model="formItem" label-position="right" :label-width="120" :rules="ruleValidate" inline>
                    <XdoFormItem prop="tradeCode" label="经营单位编码" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.tradeCode" :disabled="showDisable" xid="d_tradeCode"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="emsNo" label="账册编号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.emsNo" :disabled="showDisable" xid="d_emsNo"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="apprMaxSurpQty" label="批准最大余数量" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.apprMaxSurpQty" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_apprMaxSurpQty"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="chgApprTime" label="变更批准日期" xid="c_head_edit_form_item">
                        <XdoDatePicker type="date" format="yyyy-MM-dd" placeholder="" :value="formItem.chgApprTime ? formItem.chgApprTime.slice(0, 10) : formItem.chgApprTime" @on-change="formItem.chgApprTime=($event === '' ? $event : ($event + ' 23:59:59'))" transfer :disabled="showDisable" xid="d_chgApprTime"></XdoDatePicker>
                    </XdoFormItem>
                    <XdoFormItem prop="classMark" label="主料标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.classMark" :disabled="showDisable" xid="d_classMark"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="codeTS" label="商品编码" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.codeTS" :disabled="showDisable" xid="d_codeTS"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="consumeDiscussFlag" label="磋商标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.consumeDiscussFlag" :disabled="showDisable" xid="d_consumeDiscussFlag"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="consumeQueFlag" label="单耗质疑标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.consumeQueFlag" :disabled="showDisable" xid="d_consumeQueFlag"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="copEmsNo" label="企业内部编号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.copEmsNo" :disabled="showDisable" xid="d_copEmsNo"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="copGNo" label="料号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.copGNo" :disabled="showDisable" xid="d_copGNo"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="curr" label="币制" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.curr" :disabled="showDisable" xid="d_curr"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="cusExeMark" label="海关执行标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.cusExeMark" :disabled="showDisable" xid="d_cusExeMark"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="decPrice" label="申报单价" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.decPrice" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_decPrice"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="dutyMode" label="征免方式" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.dutyMode" :disabled="showDisable" xid="d_dutyMode"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="etpsExeMark" label="企业执行标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.etpsExeMark" :disabled="showDisable" xid="d_etpsExeMark"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="gModel" label="规格型号" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.gModel" :disabled="showDisable" xid="d_gModel"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="gName" label="商品名称" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.gName" :disabled="showDisable" xid="d_gName"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="gNo" label="序号" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.gNo" placeholder="" number int-length="9" :disabled="showDisable" xid="d_gNo"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="initialQty" label="期初数量" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.initialQty" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_initialQty"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="modifyMark" label="修改标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.modifyMark" :disabled="showDisable" xid="d_modifyMark"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="msgDecMark" label="报文控制标志" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.msgDecMark" placeholder="" number int-length="9" :disabled="showDisable" xid="d_msgDecMark"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="note" label="备注" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.note" :disabled="showDisable" xid="d_note"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="putrecApprTime" label="备案批准日期" xid="c_head_edit_form_item">
                        <XdoDatePicker type="date" format="yyyy-MM-dd" placeholder="" :value="formItem.putrecApprTime ? formItem.putrecApprTime.slice(0, 10) : formItem.putrecApprTime" @on-change="formItem.putrecApprTime=($event === '' ? $event : ($event + ' 23:59:59'))" transfer :disabled="showDisable" xid="d_putrecApprTime"></XdoDatePicker>
                    </XdoFormItem>
                    <XdoFormItem prop="qty" label="申报数量" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.qty" placeholder="" decimal int-length="13" precision="5" :disabled="showDisable" xid="d_qty"></xdo-input>
                    </XdoFormItem>
                    <XdoFormItem prop="qtyCtrlFlag" label="数量控制标志" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.qtyCtrlFlag" :disabled="showDisable" xid="d_qtyCtrlFlag"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="unit" label="申报计量单位" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.unit" :disabled="showDisable" xid="d_unit"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="unit1" label="法定计量单位" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.unit1" :disabled="showDisable" xid="d_unit1"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="unit2" label="第二计量单位" xid="c_head_edit_form_item">
                        <XdoIInput type="text" v-model="formItem.unit2" :disabled="showDisable" xid="d_unit2"></XdoIInput>
                    </XdoFormItem>
                    <XdoFormItem prop="timeStamp" label="时间戳" xid="c_head_edit_form_item">
                        <xdo-input v-model.trim="formItem.timeStamp" placeholder="" number int-length="13" :disabled="showDisable" xid="d_timeStamp"></xdo-input>
                    </XdoFormItem>
                </XdoForm>
            </div>
        </XdoCard>
        <div class="xdo-enter-action dc-edit-actions">
            <template v-for="item in buttons">
                <XdoButton v-if="item.needed === true" :type="item.type" :disabled="item.disabled"
                           :loading="item.loading"
                           @click="item.click" :icon="item.icon" :key="item.icon">{{ item.label }}
                </XdoButton>&nbsp;
            </template>
        </div>
    </section>
</template>
<script>
    import { jx_bill_testUri } from '@/api'
    import { editStatus } from '@/view/jx_bill_test-common/constant'
    import { decimalKeypress,decimalKeyup,numberKeypress,numberKeyup} from '@/libs/num'
    export default {
        name: 'EmsCusExgCurEdit',
        props: {
            editConfig: { type: Object, default: () => ({}) }
        },
        data() {
            return {
                formItem: {
                    sid: '',
                    tradeCode: '',
                    emsNo: '',
                    apprMaxSurpQty: '',
                    chgApprTime: '',
                    classMark: '',
                    codeTS: '',
                    consumeDiscussFlag: '',
                    consumeQueFlag: '',
                    copEmsNo: '',
                    copGNo: '',
                    curr: '',
                    cusExeMark: '',
                    decPrice: '',
                    dutyMode: '',
                    etpsExeMark: '',
                    gModel: '',
                    gName: '',
                    gNo: '',
                    initialQty: '',
                    modifyMark: '',
                    msgDecMark: '',
                    note: '',
                    putrecApprTime: '',
                    qty: '',
                    qtyCtrlFlag: '',
                    unit: '',
                    unit1: '',
                    unit2: '',
                    timeStamp: '',
                },
                ruleValidate: {
                            tradeCode: [
                                    { max: 10, message: '长度不能超过10位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            emsNo: [
                                    { max: 12, message: '长度不能超过12位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            apprMaxSurpQty: [
                            ],
                            chgApprTime: [
                                    { max: null, message: '长度不能超过null位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            classMark: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            codeTS: [
                                    { max: 10, message: '长度不能超过10位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            consumeDiscussFlag: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            consumeQueFlag: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            copEmsNo: [
                                    { max: 20, message: '长度不能超过20位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            copGNo: [
                                    { max: 32, message: '长度不能超过32位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            curr: [
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            cusExeMark: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            decPrice: [
                            ],
                            dutyMode: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            etpsExeMark: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            gModel: [
                                    { max: 510, message: '长度不能超过510位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            gName: [
                                    { max: 510, message: '长度不能超过510位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            gNo: [
                            ],
                            initialQty: [
                            ],
                            modifyMark: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            msgDecMark: [
                            ],
                            note: [
                                    { max: 200, message: '长度不能超过200位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            putrecApprTime: [
                                    { max: null, message: '长度不能超过null位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            qty: [
                            ],
                            qtyCtrlFlag: [
                                    { max: 1, message: '长度不能超过1位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            unit: [
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            unit1: [
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            unit2: [
                                    { max: 3, message: '长度不能超过3位字节(汉字占2位)！', trigger: 'blur' }
                            ],
                            timeStamp: [
                            ],
                },
                buttons: [
                    {
                        code: 'Save',
                        type: 'primary',
                        disabled: false,
                        click: this.handleSave,
                        label: '保存',
                        loading: false,
                        needed: true
                    },
                    {
                        code: 'Cancel',
                        type: 'primary',
                        disabled: false,
                        click: this.handleBack,
                        label: '返回',
                        loading: false,
                        needed: true
                    }
                ],
                sid: '',
                showDisable: false
            }
        },
        mounted: function(){
            if (this.editConfig && this.editConfig.editStatus === editStatus.SHOW) {
                this.formItem = { ...this.editConfig.editData }
                this.showDisable = true
                this.buttons.filter(item => item.code === "Save")[0].needed = false
                return
            }
        },
        methods: {
            resetFormData() {
                this.$refs['formItem'].resetFields()
            },
            handleSave() {
                this.$refs['formItem'].validate().then(isValid => {
                    if (isValid) {
                        let http = ''
                        this.buttons.filter(item => item.code === "Save")[0].loading = true
                        if (this.sid) {
                            http = this.$http.put(`${jx_bill_testUri.exgCurrManageUrl.emsCusExgCur.update}/${this.sid}`, this.formItem, {noIntercept: true})
                        } else {
                            http = this.$http.post(jx_bill_testUri.exgCurrManageUrl.emsCusExgCur.insert, this.formItem, {noIntercept: true})
                        }
                        http.then(res => {
                            if (res.data.success) {
                                this.$Message.success(res.data.message)
                                this.handleBack()
                            } else {
                                this.$Message.error(res.data.message)
                            }
                        }, () => {}).finally(() => {
                            this.buttons.filter(item => item.code === "Save")[0].loading = false
                        })
                    }
                })
            },
            handleBack() {
                this.$emit('onEditBack', true)
            },
            decimalKeypress,decimalKeyup,numberKeypress,numberKeyup
        }
    }
</script>
<style lang="less" scoped>
</style>
